import { IAM_SERVICE, IAM_WEB, USE_IAM } from '../lib/constants';

import request from '@/utils/request';

const prefix = `${IAM_SERVICE}/iam-service/auth`;

export const authentication = (data) => request.post(`${prefix}/login`, data);

export const register = (data) => request.post(`${prefix}/register`, data);
export const getUserInfo = () => request.get(`${prefix}/info`);
export const getUserMenu = () =>
  request.get(`${prefix}/menu`, {
    params: {
      systemCode: process.env.SYSTEM_CODE,
    },
  });

export const modifyPassword = (data) =>
  request.post(`${prefix}/modifyPassword`, data);

export const redirectLoginPage = () => {
  if (USE_IAM === '1') {
    window.location.href = `${IAM_WEB}/#/login?redirectUrl=${window.location.href}`;
  } else {
    window.location.hash = `/login?redirectPath=${window.location.hash.replace(
      '#',
      '',
    )}`;
  }
};
